<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="com.shopping.category.*" %>
<%@ include file = "_sessioncheck.jsp" %>

<%
  request.setCharacterEncoding("utf-8");
  response.setCharacterEncoding("utf-8");
  
  String strPid = request.getParameter("pid");
  int pid = 0;
  if(strPid != null) {
	  pid = Integer.parseInt(strPid);
  }
  
  String action = request.getParameter("category");
  if(action != null && action.equals("add")) {
	  String name = request.getParameter("name");
	  String descr = request.getParameter("descr");
	  if(pid == 0) {
	 	 Category.addTopCategory(name,descr);
	 	
 	 } else {
 		// Category.addChildCategory(pid,name,descr);
 	   /**
 		Category parent = new Category();
 	    parent.setId(pid);
 	    **/
 	    Category parent = Category.loadId(pid);
 	    Category child = new Category();
 	    child.setId(pid);
 	    System.out.println(parent.getId());
 	    child.setDescr(descr);
 	    child.setName(name);
 	    parent.addChild(child);
 	 }
	  out.println("Add ok");
  }
%>

<% out.print("<html>"); %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <center>添加根类别</center>
	<form action="categoryadd.jsp" method="post">
	  <input type="hidden" name="category" value="add">
	  <input type="hidden" name="pid" value="<%=pid%>">
	  <table>
	    <tr>
	      <td>类别名称</td>
	      <td><input type="text" size="20" name="name"></td>
	    </tr>
	    <tr>
	      <td>类别描述</td>
	      <td><textarea cols="40" rows="8" name="descr"></textarea></td>
	    </tr>
	    <td colspan="2"><input type="submit" value="提交"></td>
	  </table>
	</form>
</body>
</html>